package com.edu.neusoft.cookbook.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.neusoft.cookbook.common.ResponseResult;
import com.edu.neusoft.cookbook.entity.Comments;
import com.edu.neusoft.cookbook.service.CommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * (Comments)表控制层
 *
 * @author makejava
 * @since 2024-12-07 12:51:03
 */
@RestController
@Slf4j
@Api(value = "评论", tags = "评论")
@RequestMapping("/api/comments")
public class CommentsController {
    /**
     * 服务对象
     */
    @Autowired
    private CommentsService commentsService;

    /**
     * 分页查询评论信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ApiOperation("分页查询手机信息")
    @GetMapping("/page")
    public ResponseResult getByPage(@RequestParam int pageNum, @RequestParam int pageSize) {
        return ResponseResult.okResult(commentsService.findByPage(pageNum, pageSize));
    }

    /**
     * 新增评论
     *
     * @param comments 实体对象
     * @return 新增结果
     */
    @ApiOperation("新增评论")
    @PostMapping
    public ResponseResult insert(@RequestBody Comments comments) {
        return ResponseResult.okResult(this.commentsService.save(comments));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable("id") Integer id) {
        return ResponseResult.okResult(commentsService.getById(id));
    }

    /**
     * 删除评论
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("删除评论")
    @DeleteMapping
    public ResponseResult delete(@RequestParam("idList") List<Long> idList) {
        return ResponseResult.okResult(this.commentsService.removeByIds(idList));
    }
}

